package com.moorror.codegenvel.common.dialog;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;

import javax.swing.*;
import java.util.function.Function;

/**
 * @Author jiyanghuang
 * @Date 2024/4/11 23:10
 */
public class MRDialogInputName implements DialogFormMark, Disposable {

    private String inputNameText;
    private String title;
    private Project project;
    private Function<MRDialogInputName, Pair<Boolean, String>> okFun;
    @Getter
    private JTextField inputName;

    public MRDialogInputName(String inputNameText, String title, Project project, Function<MRDialogInputName, Pair<Boolean, String>> okFun) {
        this.inputNameText = inputNameText;
        this.title = title;
        this.project = project;
        this.okFun = okFun;
    }

    @Override
    public JComponent jComponent() {
        inputName = new JTextField();
        if (StringUtils.isNotBlank(inputNameText)) {
            inputName.setText(inputNameText);
        }
        return inputName;
    }

    @Override
    public <T extends DialogFormMark> Function<T, Pair<Boolean, String>> okFun() {
        return (Function<T, Pair<Boolean, String>>) okFun;
    }

    @Override
    public String title() {
        return title;
    }

    @Override
    public void dispose() {

    }
}
